<?php
class gift_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
        
    }
    function update($ID,$params){
        $this->db
                ->set('ActiveTime', 'NOW()', FALSE)
                ->where('ID', $ID)
                ->update('gift_code_513', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        //echo $this->db->last_query();
        if($count==1) return true;
        return false;
    }
    function getByUser($UserName=""){
        $d=date('d');
        $strwhere="(`UserName`='$UserName' or `UserName` is null)";
        $query=$this->db
                ->where($strwhere)
                ->order_by("UserName","DESC")
                ->get('gift_code_513',1); 
        return $query->result();
    }
    function report($StartDate="",$EndDate=""){
        $strwhere="`ActiveTime` IS NOT NULL AND 
        (
            (`ActiveTime` BETWEEN '$StartDate 00:00:00' AND '$EndDate 23:59:59') OR
            (`ActiveTime` BETWEEN '$EndDate 00:00:00' AND '$StartDate 23:59:59')
        )";
        $query=$this->db
                ->where($strwhere)
                ->order_by("ActiveTime","DESC")
                ->get('gift_code_513'); 
        return $query->result();
    }
    
}
?>
